#include <iostream>
#include <vector>
using namespace std;

vector<int> track = {};
vector<vector<int>> ans = {};
bool v[10] = {};

void dfs(int x, const vector<int> &nums) {
    if (x == nums.size()) {
        ans.push_back(track);
        return;
    }

    for (int i = 0; i < nums.size(); i++) {
        if (v[i]) continue;
        track.push_back(nums[i]);
        v[i] = 1;
        dfs(x + 1, nums);
        track.pop_back();
        v[i] = 0;
    }
}

vector<vector<int>> permute(vector<int> &nums) {
    dfs(0, nums);
    return ans;
}